package com.asiainfo.dao;
/*
 * 
 * 会员数据库操作类
 */
import java.sql.ResultSet;
import java.sql.SQLException;

import com.asiainfo.bean.VIP;
import com.asiainfo.database.JdbcTemplete;
import com.asiainfo.database.ResultSetHandler;

public class Vip_Dao {
	//添加用户
	public int add(VIP vip){
		if(findByName(vip.getName()) != null){
			return -1;
		}
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "insert into vip(vip_name,vip_address,vip_work,vip_date) values (?,?,?,?)";
		return jt.update(sql, vip.getName(),vip.getAddress(),vip.getWork(),vip.getDate());
	}
	
	public VIP findByName(String name){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "select vip_name,vip_address,vip_work,vip_date,vip_id from vip where vip_name=?";
		VIP vip = (VIP) jt.quary(sql, new ResultSetHandler() {
			public Object doHandler(ResultSet rs) throws SQLException {
				VIP vip = null;
				if (rs.next()) {
					vip = new VIP();
					vip.setName(rs.getString(1));
					vip.setAddress(rs.getString(2));
					vip.setWork(rs.getString(3));
					vip.setDate(rs.getInt(4));
					vip.setId(rs.getInt(5));
				}
				return vip;
			}
		}, name);
		return vip;
	}
}
